<?php
$arr = [
    '1'=>[
        'name'=>'the1' 
    ],
    '2'=>[
        'name'=>'the2',
        'child'=>[
            '21'=>[
                'name'=>'the21',
                'child'=>[
                    '211'=>[
                        'name'=>'the211' 
                    ],
                    '212'=>[
                        'name'=>'the212' 
                    ],
                ],
            ],
            '22'=>[
                'name'=>'the22' 
            ],
        ],
    ],
    '3'=>[
        'name'=>'the3' 
    ],
];
function whileSay($list)
{
    $onion = [];
    while(1){
        $newList = $list;
        foreach($onion as $tier){
            $newList = $newList[$tier]['child'];
        }
        $hasChild = 0;
        
        foreach($newList as $key => $item){
            if(!empty($nowtier)){
                if($key == $nowtier)
                    unset($nowtier);
                continue;
            }
            echo $item['name'].'<br />';
            if(!empty($item['child'])){
                $onion[] = $key;
                $hasChild = 1;
                break;
            }
        }
        if(empty($onion))
            break;
        if(empty($hasChild)){
            $nowtier = array_pop($onion);
        }
    }
}
whileSay($arr);

